import urllib.request
import urllib.parse
from lxml import etree

url="http://www.baidu.com"

headers={
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
}
# 请求对象的定制
request=urllib.request.Request(url=url,headers=headers)
# 模拟浏览器访问
response=urllib.request.urlopen(request)
# 获取网页源码
content=response.read().decode('utf-8')
# 解析服务器响应文件
tree=etree.HTML(content)
# 获取想要的数据 xpath返回值是一个列表
result=tree.xpath('//input[@id="su"]/@value')
print(result)
